#!/usr/bin/python
#coding=utf-8
'''
    4.8 跳过可迭代对象的开始部分
'''
# 跳过开始部分的注释的行
from itertools import dropwhile
with open('/etc/passwd') as f:
    for line in dropwhile(lambda line: line.startswith('#'), f):
        print(line, end='')

# 基于某个测试函数跳过开始的元素
from itertools import islice
items = ['a', 'b', 'c', 1, 4, 10, 15]
for x in islice(items, 3, None):
    print(x)

with open('/etc/passwd') as f:
    lines = (line for line in f if not line.startswith('#'))
    for line in lines:
        print(line, end='')